package com.class05.advice;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/11/1 19:41
 * 加入ioc容器  @Component
 * 配置切面注解 @Aspect = 切点+增强
 * spring aop重点是配置  ——> jdk  |  cglib
 */
@Component
@Aspect
public class LogAdvice {
    // @Before注解：声明当前方法是前置通知方法
    // value属性：指定切入点表达式，由切入点表达式控制当前通知方法要作用在哪一个目标方法上
    @Before(value = "execution(public int com.class05.service.impl.CalculatorPureImpl.add(int,int))")
    public void start() {
        System.out.println("[AOP前置通知] 方法开始了");
    }

    @After(value = "execution(public int com.class05.service.impl.CalculatorPureImpl.add(int,int))")
    public void after() {
        System.out.println("方法结束了");
    }

    @AfterThrowing(value = "execution(public int com.class05.service.impl.CalculatorPureImpl.add(int,int))")
    public void error() {
        System.out.println("方法报错了");
    }
}
